<?php
namespace app\common\model\users;

use think\Model;
use think\Db;

/*************************************************  
*ClassName:     UsersWithdrawals
*Description:   用户提现模型
*Others:        
*************************************************/
class UsersWithdrawals extends Model
{   
    /**
     * getInfo 用户申请提现记录
     * @xiao
     * @DateTime 2016-07-31T23:23:02+0800
     * @param    int                   $uid
     * @param    array                 $data
     * @return   array                 [error_code,  error_msg]
     */
    static public function getInfo($uid, $data = '')
    {   
        $data['uid'] = $uid;
        $res = Db::name('users_withdrawals')->where($data)->find();
        if ($res) {
            $result['error_code'] = 0;
            $result['error_msg'] = "";
            $result['data'] = $res;
        }else{
            $result['error_code'] = 1;
            $result['error_msg'] = "查询失败";
        }
        return $result;
    }

    /**
     * add 申请提现
     * @xiao
     * @DateTime 2016-07-31T23:23:02+0800
     * @param    array                 $data
     * @return   array                 [error_code,  error_msg]
     */
    static public function add($data)
    {
        $res = Db::name('users_withdrawals')->insertGetId($data);
        if ($res) {
            $result['error_code'] = 0;
            $result['error_msg'] = "";
            $result['id'] = $res;
        }else{
            $result['error_code'] = 1;
            $result['error_msg'] = "查询失败";
        }
        return $result;
    }

    /**
     * agree 同意
     * @karl
     * @DateTime 2017-04-21T08:50:48+0800
     * @param    int                   $id      操作id
     * @return   array                 [error_code,  error_msg]
     */
    static public function agree($id)
    {
       if(Db::name('users_withdrawals')->where(['id' => $id])->update(['agree'=> 0])){
           $result['error_code'] = 0;
           $result['error_msg'] = "";
       }else{
           $result['error_code'] = 1;
           $result['error_msg'] = "查询失败";
       }
       return $result;
    }

    /**
     * refuse 拒绝
     * @karl
     * @DateTime 2017-04-21T08:50:48+0800
     * @param    int                   $id      操作id
     * @return   array                 [error_code,  error_msg]
     */
    static public function refuse($id)
    {
        if(Db::name('users_withdrawals')->where(['id' => $id])->update(['agree'=> 2])){
            $result['error_code'] = 0;
            $result['error_msg'] = "";
        }else{
            $result['error_code'] = 1;
            $result['error_msg'] = "查询失败";
        }
        return $result;
    }

}

?>